import { userInfo } from 'os';

export const ProjectConfig: ProjectConfigType = [
  {
    label: '推广目的',
    show: true,
    list: [
      {
        label: '推广目的',
        field: 'landingType',
        list: [
          {
            label: '小程序',
            value: 'MICRO_GAME'
          }
        ],
        type: 'radio',
        isCanSelect: false,
        show: true
      },
      {
        label: '广告类型',
        field: 'adType',
        list: [
          {
            label: '通投广告',
            value: 'ALL'
          }
        ],
        type: 'radio',
        isCanSelect: false,
        show: true
      },
      {
        label: '投放类型',
        field: 'deliveryType',
        list: [
          {
            label: '常规投放',
            value: 'NORMAL'
          }
        ],
        type: 'radio',
        isCanSelect: false,
        show: true
      },
      {
        label: '投放模式',
        field: 'deliveryMode',
        list: [
          {
            label: '手动投放',
            value: 'MANUAL'
          },
          {
            label: '自动投放',
            value: 'PROCEDURAL'
          }
        ],
        type: 'radio',
        isCanSelect: true,
        show: true
      },
      {
        label: '营销场景',
        field: 'marketingGoal',
        list: [
          {
            label: '短视频/图片',
            value: 'VIDEO_AND_IMAGE'
          },
          {
            label: '直播',
            value: 'LIVE'
          }
        ],
        type: 'radio',
        isCanSelect: false,
        show: true
      }
    ]
  },
  {
    label: '关联商品投放',
    show: true,
    list: [
      {
        label: '关联商品',
        field: 'productSetting',
        list: [
          {
            label: '不启用',
            value: 'NO_MAP'
          },
          {
            label: '启用',
            value: 'SINGLE'
          }
        ],
        type: 'radio',
        supField: 'relatedProduct',
        isCanSelect: true,
        show: true
      },
      {
        label: '匹配方式',
        field: 'projectProductWay',
        list: [
          {
            label: '所有项目选择同一组产品',
            value: 1
          },
          {
            label: '每个账户选择一组产品',
            value: 2
          },
          {
            label: '每个项目选择一组产品',
            value: 3
          }
        ],
        type: 'radio',
        isCanSelect: false,
        show: true
      },
      {
        label: '选择商品',
        field: 'productId',
        showField: 'productName',
        type: 'components',
        componentRef: 'dramaRef',
        openType: 'button',
        openText: '选择商品',
        supField: 'relatedProduct',
        isCanSelect: false,
        show: true
      }
    ]
  },
  {
    label: '素材补充方式',
    show: true,
    list: [
      {
        label: 'AIGC动态创意',
        field: 'aigcDynamicCreativeSwitch',
        list: [
          {
            label: '不启用',
            value: 'OFF'
          },
          {
            label: '启用',
            value: 'ON'
          }
        ],
        type: 'radio',
        isCanSelect: true,
        show: true
      },
      
    ]
  },
  {
    label: '投放内容与目标',
    show: true,
    list: [
      {
        label: '投放载体',
        field: 'microPromotionType',
        list: [
          {
            label: '微信小程序',
            value: 'WECHAT_APP'
          },
          {
            label: '字节小程序',
            value: 'BYTE_APP'
          },
          {
            label: '抖音号',
            value: 'AWEME'
          }
        ],
        type: 'radio',
        isCanSelect: true,
        show: true
      },
      {
        label: '小程序',
        field: 'microAppInstanceId',
        type: 'components',
        componentRef: 'microAppRef',
        openType: 'button',
        openText: '',
        changeCondition: 'microPromotionType',
        isCanSelect: false,
        show: true
      },
      {
        label: '优化目标',
        field: 'externalAction',
        list: [],
        type: 'select',
        supField: 'optimizeGoal',
        isCanSelect: true,
        show: true,
        isRemote: true
      },
      {
        label: '深度优化目标',
        field: 'deepExternalAction',
        list: [],
        type: 'select',
        supField: 'optimizeGoal',
        isCanSelect: true,
        show: true
      }
    ]
  },
  {
    label: '投放版位',
    show: false,
    list: [
      {
        label: '广告位置',
        field: 'inventoryCatalog',
        list: [
          {
            label: '通投智选',
            value: 'UNIVERSAL_SMART',
            tips: '通投智选下，广告会投到信息流和搜索场景，提升单计划跑量与效果稳定性'
          },
          {
            label: '首选媒体',
            value: 'MANUAL',
            tips: '广告将主要投放在首选媒体上，同时为了帮助广告计划更好的跑量和优化成本，系统有可能将广告智能拓展投放到其他流量场景。'
          }
        ],
        type: 'radio',
        supField: 'deliveryRange',
        isCanSelect: true,
        show: true
      }
    ]
  },
  {
    label: '用户定向',
    show: true,
    list: [
      {
        label: '地域',
        field: 'district',
        list: [
          {
            label: '不限',
            value: 'NONE'
          },
          {
            label: '按行政区域划分',
            value: 'REGION'
          }
          // {
          //   label: '按商圈',
          //   value: 2
          // }
        ],
        type: 'radio',
        isCanSelect: true,
        supField: 'audience',
        show: true
      },
      {
        label: '性别',
        field: 'gender',
        list: [
          {
            label: '不限',
            value: 'NONE'
          },
          {
            label: '男',
            value: 'GENDER_MALE'
          },
          {
            label: '女',
            value: 'GENDER_FEMALE'
          }
        ],
        type: 'radio',
        isCanSelect: true,
        supField: 'audience',
        show: true
      },
      {
        label: '年龄',
        field: 'age',
        list: [
          {
            label: '不限',
            value: ''
          },
          {
            label: '18-23',
            value: 'AGE_BETWEEN_18_23'
          },
          {
            label: '24-30',
            value: 'AGE_BETWEEN_24_30'
          },
          {
            label: '31-40',
            value: 'AGE_BETWEEN_31_40'
          },
          {
            label: '41-50',
            value: 'AGE_BETWEEN_41_49'
          },
          {
            label: '50+',
            value: 'AGE_ABOVE_50'
          }
        ],
        type: 'checkbox',
        isCanSelect: true,
        supField: 'audience',
        show: true
      },
      {
        label: '自定义人群',
        field: '',
        list: [
          {
            label: '不限',
            value: 0
          },
          {
            label: '自定义',
            value: 1
          }
        ],
        type: 'radio',
        isCanSelect: false,
        show: true
      },
      
      {
        label: '平台',
        field: 'platform',
        list: [
          {
            label: '不限',
            value: []
          },
          {
            label: 'iOS',
            value: ['IOS']
          },
          {
            label: 'Android',
            value: ['ANDROID']
          }
        ],
        type: 'radio',
        isCanSelect: true,
        supField: 'audience',
        show: true
      },
      {
        label: '过滤已转化用户',
        field: 'hideIfConverted',
        list: [
          {
            label: '不限',
            value: 'NO_EXCLUDE'
          },
          {
            label: '广告',
            value: 'PROMOTION'
          },
          {
            label: '项目',
            value: 'PROJECT'
          },
          {
            label: '广告账户',
            value: 'ADVERTISER'
          },
          {
            label: '公司账户',
            value: 'CUSTOMER'
          },
          {
            label: '组织账户',
            value: 'ORGANIZATION'
          }
        ],
        type: 'radio',
        isCanSelect: false,
        supField: 'audience',
        show: true
      },
      {
        label: '行为兴趣',
        field: 'interestActionMode',
        list: [
          {
            label: '不限',
            value: 'UNLIMITED'
          },
          {
            label: '系统推荐',
            value: 'RECOMMEND'
          },
          // {
          //   label: '自定义',
          //   value: 1
          // }
        ],
        type: 'radio',
        isCanSelect: true,
        supField: 'audience',
        show: false
      },
    ]
  },
  {
    label: '项目排期与预算',
    show: true,
    list: [
      {
        label: '投放时间',
        field: 'scheduleType',
        list: [
          {
            label: '从今天起长期投放',
            value: 'FROM_NOW'
          },
          {
            label: '设置开始和结束日期',
            value: 'START_END'
          }
        ],
        type: 'radio',
        supField: 'deliverySetting',
        isCanSelect: true,
        show: true
      },
      {
        label: '投放时段',
        field: 'scheduleTimeType',
        list: [
          {
            label: '不限',
            value: 0
          },
          {
            label: '指定时段',
            value: 1
          }
        ],
        type: 'radio',
        supField: 'deliverySetting',
        isCanSelect: true,
        show: true
      },
      {
        label: '竞价策略',
        field: 'bidType',
        list: [
          {
            label: '稳定成本',
            value: 'CUSTOM'
          },
          {
            label: '最优成本',
            value: 'UPPER_CONTROL'
          },
          {
            label: '最大转化',
            value: 'NO_BID'
          }
        ],
        type: 'radio',
        supField: 'deliverySetting',
        isCanSelect: true,
        show: true
      },
      {
        label: '预算择优分配',
        field: 'budgetOptimizeSwitch',
        list: [
          {
            label: '不启用',
            value: 'OFF'
          },
          {
            label: '启用',
            value: 'ON'
          }
        ],
        type: 'radio',
        supField: 'deliverySetting',
        isCanSelect: true,
        show: false
      },
      {
        label: '预算类型',
        field: 'budgetMode',
        list: [
          {
            label: '日预算',
            value: 'DAY'
          }
        ],
        type: 'radio',
        supField: 'deliverySetting',
        isCanSelect: true,
        show: true
      },
      // {
      //   label: '系数出价',
      //   field: 'deepBidType',
      //   list: [
      //     {
      //       label: '系数出价',
      //       value: 'ROI_COEFFICIENT'
      //     }
      //   ],
      //   type: 'radio',
      //   supField: 'deliverySetting',
      //   isCanSelect: true,
      //   show: true
      // },
      {
        label: '日预算',
        field: 'budget',
        type: 'input',
        inputType: 'number',
        min: 300,
        max: 99999999.99,
        supField: 'deliverySetting',
        isCanSelect: true,
        tips: '预算不少于300元，不超过9999999.99元',
        show: true
      },
      {
        label: '付费方式',
        field: 'pricing',
        list: [
          {
            label: '展示付费',
            value: 'OCPM'
          }
        ],
        type: 'radio',
        supField: 'deliverySetting',
        isCanSelect: false,
        show: true
      },
      {
        label: '出价',
        field: 'cpaBid',
        type: 'input',
        inputType: 'number',
        min: 0.2,
        max: 999,
        supField: 'deliverySetting',
        isCanSelect: true,
        tips: '不少于0.2元，不超过999元',
        show: true
      },
      {
        label: '出价系数',
        field: 'searchBidRatio',
        type: 'input',
        inputType: 'number',
        min: 1,
        max: 2,
        isCanSelect: true,
        tips: '不小于1，不超过2',
        show: false
      },
      {
        label: '定向拓展',
        field: 'audienceExtend',
        list: [
          {
            label: '不启用',
            value: 'OFF'
          },
          {
            label: '启用',
            value: 'ON'
          }
        ],
        type: 'radio',
        isCanSelect: true,
        show: true
      },
      {
        label: 'ROI系数',
        field: 'roiGoal',
        type: 'input',
        inputType: 'number',
        min: 0.01,
        max: 5,
        supField: 'deliverySetting',
        isCanSelect: true,
        tips: '不小于0.01，不超过5,支持最多四位小数',
        show: true
      }
    ]
  },
  {
    label: '项目名称',
    show: true,
    list: [
      {
        label: '项目名称',
        field: 'name',
        type: 'input',

        isCanSelect: false,
        tips: '目前仅支持<日期><花名><剧名><编号>四个字段',
        show: true
      },
      {
        label: '项目状态',
        field: 'operation',
        type: 'radio',
        list: [
          {
            label: '关闭',
            value: 'DISABLE'
          },
          {
            label: '开启',
            value: 'ENABLE'
          }
        ],
        isCanSelect: true,
        show: true
      }
    ]
  }

  // {
  //   label: 'AIGC动态创意',
  //   list: [
  //     {
  //       label: 'AIGC动态创意',
  //       field: ' ',
  //       list: []
  //     }
  //   ]
  // }
];

export interface Option {
  label: string;
  value: string | number | boolean | string[]; // 可以是字符串、数字或布尔值
  tips?: string;
}

export interface Item {
  label: string;
  field: string;
  list?: Option[];
  type: 'radio' | 'select' | 'components' | 'input' | 'checkbox'; // 根据需要扩展类型
  openType?: string;
  openText?: string;
  componentRef?: string;
  supField?: string;
  isCanSelect: boolean;
  showField?: string; // 可选属性
  changeCondition?: string | number;
  inputType?: string;
  min?: number;
  max?: number;
  tips?: string;
  show: boolean;
  isRemote?: boolean;
}

interface Category {
  label: string;
  show: boolean;
  list: Item[];
}

export type ProjectConfigType = Category[];

export interface RelatedProductType {
  productSetting: 'SINGLE' | 'NO_MAP';
  productPlatformId: number;
  productId: number | string;
  productName: string;
}
type SelectAppInfoType = {
  id: number | string;
  name: string;
  appId?: string;
  appName?: string;
  instanceId?: string;
};
export interface ProjectForm {
  landingType: 'MICRO_GAME';
  adType: 'ALL';
  deliveryType: 'NORMAL';
  deliveryMode: 'MANUAL' | 'PROCEDURAL';
  marketingGoal: 'VIDEO_AND_IMAGE' | 'LIVE';
  isRelatedgoods: 'NO_MAP' | 'SINGLE';
  projectProductWay: 1 | 2 | 3;
  relatedProduct: RelatedProductType;
  microPromotionType: 'WECHAT_APP' | 'BYTE_APP' | 'AWEME';
  microAppInstanceId: number;
  aigcDynamicCreativeSwitch: 'ON'|'OFF';
  audienceExtend?: 'OFF'|'ON'|null;
  searchBidRatio?: number;
  deliveryRange: {
    inventoryCatalog: 'UNIVERSAL_SMART' | 'MANUAL';
    inventoryType: [];
  };
  optimizeGoal: {
    externalAction: string; //
    deepExternalAction: string;
    assetIds?: number[] | string[];
  };
  deliverySetting: {
    scheduleType: 'FROM_NOW' | 'START_END' | 'SCHEDULE_7_DAYS'; //FROM_NOW 从今天起长期投放  START_END 设置开始和结束日期  SCHEDULE_7_DAYS 7日稳投new
    startTime: string;
    endTime: string;
    scheduleTime: string;
    scheduleTimeType: 0 | 1; //0 全天 1 指定时段
    bidType: 'CUSTOM' | 'NO_BID' |'UPPER_CONTROL';
    pricing: 'OCPM';
    cpaBid?: number;
    budget?: number;
    budgetMode?: 'DAY';
    deepBidType?: 'ROI_COEFFICIENT';
    roiGoal?: number;
    budgetOptimizeSwitch?:'OFF'|'ON'|null;
    
    // deepBidType: '';
  };
  userInfo: SelectAppInfoType[];
  audience: {
    platform: [] | ['IOS'] | ['ANDROID'];
    hideIfConverted: 'NO_EXCLUDE' | 'PROMOTION' | 'PROJECT' | 'ADVERTISER' | 'APP' | 'CUSTOMER' | 'ORGANIZATION';
    gender: 'NONE' | 'GENDER_FEMALE' | 'GENDER_MALE';
    age?: string[];
    district: 'NONE' | 'REGION' | 'BUSINESS_DISTRICT' | 'OVERSEA';
    city?: string[];
    locationType: 'CURRENT' | 'HOME' | 'TRAVEL' | 'ALL';
    interestActionMode: 'UNLIMITED' | 'RECOMMEND';
  };
  name: string;
  operation: 'ENABLE' | 'DISABLE';
}

export const initFormData: ProjectForm = {
  landingType: 'MICRO_GAME',
  adType: 'ALL',
  deliveryType: 'NORMAL',
  deliveryMode: 'PROCEDURAL',
  marketingGoal: 'VIDEO_AND_IMAGE',
  isRelatedgoods: 'NO_MAP',
  projectProductWay: 1,
  microPromotionType: 'WECHAT_APP',
  microAppInstanceId: null,
  aigcDynamicCreativeSwitch: 'OFF',
  audienceExtend: 'OFF',
  searchBidRatio: undefined,
  relatedProduct: {
    productSetting: 'SINGLE',
    productPlatformId: null,
    productId: null,
    productName: null
  },
  deliveryRange: {
    inventoryCatalog: 'UNIVERSAL_SMART',
    inventoryType:[]
  },
  optimizeGoal: {
    externalAction: null,
    deepExternalAction: null,
    assetIds: null
  },
  deliverySetting: {
    scheduleType: 'FROM_NOW',
    startTime: null,
    endTime: null,
    scheduleTime: undefined,
    scheduleTimeType: 0,
    bidType: 'CUSTOM',
    pricing: 'OCPM',
    cpaBid: null,
    budget: null,
    budgetMode: 'DAY',
    deepBidType: null, // ROI_COEFFICIENT 抖音号不需要
    roiGoal: null,
    budgetOptimizeSwitch:undefined,
 
  },
  userInfo: null,
  audience: {
    platform: [],
    hideIfConverted: 'PROMOTION',
    gender: 'NONE',
    age: [],
    district: 'NONE',
    city: [],
    locationType: 'CURRENT',
    interestActionMode:undefined,
  },
  name: '<日期>-<花名>-<剧名>-<编号>',
  operation: 'ENABLE'
};

export const ProjectRules = {
  'optimizeGoal.externalAction': [{ required: true, message: '请选择优化目标', trigger: 'change' }],
  // 'optimizeGoal.deepExternalAction': [{ required: true, message: '请选择深度优化目标', trigger: 'change' }],
  // 'relatedProduct.productId': [{ required: true, message: '请选择商品', trigger: 'blur' }],
  userInfo: [
    {
      validator: (rule, value, callback) => {
        if (!Array.isArray(value) || value.length === 0) {
          callback(new Error('用户信息不能为空'));
        } else {
          callback();
        }
      },
      trigger: 'blur'
    }
  ],
  'deliverySetting.budget': [{ required: true, message: '日预算不能为空', trigger: 'blur' }],
  'deliverySetting.bid': [{ required: true, message: '出价不能为空', trigger: 'blur' }],
  'deliverySetting.roiGoal': [{ required: true, message: 'ROI系数不能为空', trigger: 'blur' }],
  'name': [{ required: true, message: '项目名称格式不能为空', trigger: 'blur' }]
};
